package MapClass.Trip;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class Tripitem  implements WritableComparable<Tripitem> {
    private String vin;

    private int mileage;

    private int minutes;

    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    public int getMileage() {
        return mileage;
    }

    public void setMileage(int mileage) {
        this.mileage = mileage;
    }

    public int getMinutes() {
        return minutes;
    }

    public void setMinutes(int minutes) {
        this.minutes = minutes;
    }


    public Tripitem(){}

    public Tripitem(String vin, int mileage, int minutes) {
        this.vin = vin;
        this.mileage = mileage;
        this.minutes = minutes;
    }



        @Override
    public int compareTo(Tripitem another) {
        if(mileage > another.getMileage()){
            return -1;
        } else if (mileage == another.mileage) {
            if (minutes > another.getMinutes()){
                return 1;
            }else {
                return 0;
            }

        }else {
            return 1;
        }
    }





    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.vin = dataInput.readUTF();
        this.mileage = dataInput.readInt();
        this.minutes = dataInput.readInt();

    }


    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(this.vin);

        dataOutput.writeInt(this.mileage);

        dataOutput.writeInt(this.minutes);

    }


    @Override
    public String toString(){
        return String.format("%s %s %s", vin, mileage, minutes);
    }
}




